﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Wilson/MP/Base.Master" AutoEventWireup="true" CodeBehind="AdIndexCreate.aspx.cs" Inherits="WebsiteAdmin.Wilson.AdInfo.AdIndexCreate" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head_Title" runat="server">新增首页广告 - 广告</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Head_Meta" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Head_Css" runat="server">
    <link rel='stylesheet' type='text/css' href='/css/datepicker_vista/datepicker_vista.css' />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Head_Script" runat="server">
    <script type="text/javascript" src="/Script/Mootools.Smoothbox.js"></script>
	<script type="text/javascript" src="/CKEditor/CKEditor.js"></script>
	<script type="text/javascript" src="/CKFinder/CKFinder.js"></script>	
    <script type="text/javascript" src="/Script/datepicker.js"></script>
    <script type="text/javascript" language="javascript">
        var MenuViewID = 3;
        Array.implement({
            getFirstRadio: function() {
                if (this.length == 0) {
                    return null;
                }
                return this[0];
            }
        });
        window.addEvent('domready', function() {
            if (typeof (CKEDITOR) == 'undefined' || typeof (CKFinder) == 'undefined') {
                alert('加载CKEditor或CKFinder失败');
            } else {
                CKFinder.setupCKEditor(null, '/CKFinder/');
                CKEDITOR.replace('txbAdContent');
            }
            
            $('submitbtn').addEvent('click', function() {
                Submit();
            });
            
            new DatePicker($('txbDateStart'), {
		            pickerClass: 'datepicker_vista',
		            format: 'Y-m-d',
		            inputOutputFormat: 'Y-m-d',
		            yearPicker: false,
		            allowEmpty: false,
		            toggleElements: $('CalendarTrigger2')
		        });
		        new DatePicker($('txbDateEnd'), {
		            pickerClass: 'datepicker_vista',
		            format: 'Y-m-d',
		            inputOutputFormat: 'Y-m-d',
		            yearPicker: false,
		            allowEmpty: false,
		            toggleElements: $('CalendarTrigger3'),
		            onSelect: function(d) {
		                var startD = $('txbDateStart').get('value');
		                var dd = d.diff(startD) + 1;
		                if (dd < 0) {
		                    $('txbDateEnd').getNext('i').set('text', '相隔 ' + (-dd) + ' 天');
		                }
		                else {
		                    alert('日期至少相隔1天');
		                    $('txbDateEnd').getNext('i').set('text', '');
		                }
		            }
		        });

		        $('ShowLink').addEvent('click', function() {
		            BrowseServer('Images:/Ad/HomePage/', 'txbImgURL', 'ShowView');

		        });
            
        });

        function SetFileField(fileUrl, data) {
            $(data["selectActionData"]).value = fileUrl;
            $(this).setProperty('src', fileUrl);
        }
        function BrowseServer(startupPath, functionData, element) {
            var finder = new CKFinder();
            finder.startupPath = startupPath;
            finder.selectActionData = functionData;
            finder.selectActionFunction = SetFileField.bind(element);
            finder.popup();
        }

        function getContents(e) {
            var oEditor = CKEDITOR.instances[e];
            if (oEditor != null) {
                return (oEditor.getData());
            } else {
                return "";
            }
        }
        
        function Submit() {
            var txbCatID = 0;
            
            var txbAdTitle = $('txbAdTitle').get('value').trim();
            if (txbAdTitle.length == 0) {
                alert('请输入广告标题');
                return false;
            }
            var txbKeywords = $('txbKeywords').get('value').trim();
            var txbDescription = $('txbDescription').get('value').trim();
            var txbLinkURL = $('txbLinkURL').get('value').trim();
            if (txbLinkURL.length == 0) {
                alert('请输入广告连接地址');
                return false;
            }
            var txbImgURL  = $('txbImgURL').get('value').trim();
            
            var txbAdContent = getContents('txbAdContent').trim();
            if (txbAdContent.length == 0) {
                alert('请输入广告内容');
                return false;
            }
            
            var startDate = $('txbDateStart').value;
		    var endDate = $('txbDateEnd').value;
            
            Update(
                txbCatID,
                txbAdTitle,
                txbKeywords,
                txbDescription,
                txbLinkURL,
                txbImgURL,
                txbAdContent,
                startDate,
                endDate);
        }
        
        function Update(txbCatID,
                txbAdTitle,
                txbKeywords,
                txbDescription,
                txbLinkURL,
                txbImgURL,
                txbAdContent,
                startDate,
                endDate) {

            new Request.JSON({
                method: 'post',
                url: 'Handler/Create.ashx',
                data: {
                    AdType:3,
                    CatID: txbCatID,
                    AdTitle: txbAdTitle,
                    Keywords : txbKeywords,
                    Description: txbDescription,
                    LinkURL:txbLinkURL,
                    ImgURL : txbImgURL,
                    AdContent : txbAdContent,
                    StartDate : startDate,
                    EndDate : endDate
                },
                noCache: true,
                onSuccess: function(data, text) {
                    if (data.Done == 'Success') { 
                        
                        if(confirm('修改成功，返回列表？'))
                        {
                            document.location.href = '/Wilson/AdInfo/AdIndexList.aspx';
                        };
                        LightBox.remove();
                    }
                    else
                    {
                        alert('修改失败');
                        LightBox.remove();
                    }
                },
                onFailure: function(xhr) {
                    alert(xhr.statusText);
                    LightBox.remove();
                }
            }).send();
        }
    </script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Body_Top" runat="server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Body_Content" runat="server">
    <div class="infobox">
        <h3>
        <span>新增首页广告</span>
			<a href="/Wilson/AdInfo/AdIndexList.aspx" class="back action">返回列表</a>
        </h3>
        <div class="pd05">
        <form id="myForm" action="">
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
		        <tr>
            		<td align="right" width="100"><span class="Need">广告标题：</span></td>
            		<td>
            			<input name="txbAdTitle" type="text" id="txbAdTitle" maxlength="20" size="40" value="" />
            		</td>
				</tr>
				
				<tr>
            		<td align="right" width="100">关键词：</td>
            		<td>
            			<input name="txbKeywords" type="text" id="txbKeywords" maxlength="50" size="50" value="" />
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">简介：</span></td>
            		<td>
            			<textarea name="txbDescription" rows="3" cols="20" id="txbDescription"></textarea>
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">链接地址：</span></td>
            		<td>
            			<input name="txbLinkURL" type="text" id="txbLinkURL" maxlength="200" size="76" value="" />.html
            		</td>
				</tr>
				<tr>
                    <td align="right" width="100">
                        图片：</td>
                    <td>
                           <input type="text" id="txbImgURL" name="txbImgURL" style="width:450px; color:#666; background-color:#efefef; border:1px #ccc solid;" readonly="readonly" value=""  /> <font color="red">*&nbsp;</font>
                           <a id="ShowLink" style="cursor:pointer;cursor:hand;border:solid 1px;padding:0 10px 0 10px;">浏览</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="100">&nbsp;</td>
                    <td>
                        <div style=" width:316px; height:124px; overflow:hidden; border:1px #999 solid; background-color:#f8f8f8; clear:both;">
                           <img id="ShowView" alt="" src="/images/view.png" />
                        </div>
                        <i>图片尺寸 316 x 124。</i><br />
                        <i>如果图片不能完全填充，请重新选择图片。</i>
                    </td>
                </tr>
                <tr>
					<td align="right"><span class="Need">广告内容：</span></td>
					<td>
						<textarea name="txbAdContent" rows="14" cols="20" id="txbAdContent"></textarea>
						<i>限2000汉字(4000字符)</i>
					</td>
				</tr>
				<tr>
            
                    <td align="right"><span class="Need">日期：</span></td>
				    <td>
					    <input name="txbDateStart" type="text" id="txbDateStart" maxlength="50" value="<%=startDate %>" readonly="readonly" />
					    <img alt="" src="../../css/datepicker_vista/calendar.gif" id="CalendarTrigger2" />
					    -
					    <input name="txbDateEnd" type="text" id="txbDateEnd" maxlength="50" value="<%=endDate %>"  readonly="readonly" />
					    <img alt="" src="../../css/datepicker_vista/calendar.gif" id="CalendarTrigger3" />
					    <i></i>
				    </td>
                </tr>
                
		    </table>
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
				<tr>
					<td width="100" height="40">&nbsp;</td>
					<td>
						<input id="submitbtn" type="button" value="提交" class="btn" />
						<input type="reset" value="重置" class="btn" />
					</td>
				</tr>
			</table>
		</form>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="Body_Foot" runat="server">
</asp:Content>
